package com.haobangs.imms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.haobangs.imms.mapper.WorkshopMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.haobangs.imms.domain.Workshop;
import com.haobangs.imms.service.IWorkshopService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车间管理Controller
 *
 * @author ruoyi
 * @date 2023-06-12
 */
@RestController
@RequestMapping("/imms/workshop")
public class WorkshopController extends BaseController
{
    @Autowired
    private IWorkshopService workshopService;

    @Autowired
    private WorkshopMapper workshopMapper;

    /**
     * 分页查询车间管理列表
     */
//    @PreAuthorize("@ss.hasPermi('imms:workshop:list')")
    @GetMapping("/page")
    public Page getByPage(Workshop workshop)
    {
       return workshopService.getByPage(workshop);
    }

    /**
     * 查询车间管理列表
     */
//    @PreAuthorize("@ss.hasPermi('imms:workshop:list')")
    @GetMapping("/list")
    public AjaxResult getList()
    {
        return AjaxResult.success(workshopMapper.selectList(null));
    }

    /**
     * 导出车间管理列表
     */
//    @PreAuthorize("@ss.hasPermi('imms:workshop:export')")
    @Log(title = "车间管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Workshop workshop)
    {
        List<Workshop> list = workshopService.selectWorkshopList(workshop);
        ExcelUtil<Workshop> util = new ExcelUtil<Workshop>(Workshop.class);
        util.exportExcel(response, list, "车间管理数据");
    }

    /**
     * 获取车间管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('imms:workshop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(workshopService.selectWorkshopById(id));
    }

    /**
     * 新增车间管理
     */
//    @PreAuthorize("@ss.hasPermi('imms:workshop:add')")
    @Log(title = "车间管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Workshop workshop)
    {
        return toAjax(workshopService.insertWorkshop(workshop));
    }

    /**
     * 修改车间管理
     */
//    @PreAuthorize("@ss.hasPermi('imms:workshop:edit')")
    @Log(title = "车间管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Workshop workshop)
    {
        return toAjax(workshopService.updateWorkshop(workshop));
    }

    /**
     * 删除车间管理
     */
//    @PreAuthorize("@ss.hasPermi('imms:workshop:remove')")
    @Log(title = "车间管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workshopService.deleteWorkshopByIds(ids));
    }
}
